
const express = require('express')
const app = express()   //生成一个app
const {buildSchema}=require("graphql") //用于创建schema
const {graphqlHTTP} = require('express-graphql')//实现关联
const port = 3000

let Schema=buildSchema(`
    type Query{
        hello:String,
        getNumber:Int
    }
`)   //创建一个sccama

// resolve处理器-根据字段返回
const root={
    hello:()=>{
        //通过数据库查询
        let str="hello world"
        return str
    },
    getNumber:()=>{
        return 100
    }
}
// use：app请求处理器
app.use('/home',(req,res)=>{
    res.send('hello 999999999')
})

app.use('/graphql',graphqlHTTP({
    schema:Schema,
    rootValue:root,
    graphiql:true //开启调试器c
}))
// app.get('/', (req, res) => {
//   res.send('Hello World!')
// })


app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})